package com.ax.center.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author zy
 * @date 2023/7/10 13:25
 */

@Configuration
public class TaskSchedulerConfig {
    @Bean
    public TaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler taskScheduler =new ThreadPoolTaskScheduler();
        // 进行 TaskScheduler 的配置，例如设置线程池大小、线程名前缀等
        taskScheduler.setPoolSize(10);
        taskScheduler.setThreadNamePrefix("MyTaskScheduler");
        taskScheduler.setRemoveOnCancelPolicy(false);
        taskScheduler.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        return taskScheduler;
    }
}

